📐 ConstructQ · Workflow Lifecycle — ER Diagram v2.0

9 tables · state machine · templates · deployments · runtime tracking
🔑 PK
🔗 FK
Enum
Master
Structure
Deployment
Aux
Audit
Runtime
Enum
Master
Structure
Deploy / Aux
Runtime / Audit
workflow_states7 rows
idVARCHAR(30)
name_th · enVARCHAR
colorVARCHAR(20)
iconVARCHAR(20)
sort_orderINT
created/assigned/in_progress/review/done/blocked/rejected
workflow_templatesMaster
idBIGSERIAL
codeVARCHAR(40) UQ
name_th · name_enVARCHAR
desc_th · desc_enTEXT
iconVARCHAR(20)
categoryVARCHAR(40)
statusVARCHAR(20)
organization_id→ orgs
created_by→ users
3 templates in v2.0 seed
workflow_stepsSLA + role
idBIGSERIAL
template_id→ templates
step_idVARCHAR(30)
state_id→ states
roleVARCHAR(50)
sla_hoursINT
note_th · enTEXT
One row per state used in workflow
workflow_transitionsEdges
idBIGSERIAL
template_id→ templates
transition_idVARCHAR(30)
from_state→ states
to_state→ states
triggerVARCHAR(30)
label_th · enVARCHAR
conditionTEXT (JSON)
auto · pass · fail · action · manual · system
workflow_deploymentsLive
idBIGSERIAL
codeVARCHAR(40) UQ
template_id→ templates
template_versionVARCHAR(10)
name_th · enVARCHAR
is_defaultBOOLEAN
tasks_usingINT
deployed_by→ users
workflow_template_versionsSnapshot
idBIGSERIAL
template_id→ templates
versionVARCHAR(10)
snapshotJSONB
published_by→ users
workflow_tagsM:N
idBIGSERIAL
template_id→ templates
tagVARCHAR(40)
task_state_historyRuntime
idBIGSERIAL
task_id→ tasks
deployment_id→ deployments
from_state · to→ states
triggerVARCHAR(30)
actor_id→ users
elapsed_hoursNUMERIC
commentTEXT
transitioned_atTIMESTAMPTZ
Every state change logged
workflow_template_auditTrail
idBIGSERIAL
template_id→ templates
actor_id→ users
action · fieldVARCHAR
change_summaryTEXT
diffJSONB

🔗 ความสัมพันธ์ระหว่างตาราง

workflow_templates─1:N→workflow_steps
workflow_templates─1:N→workflow_transitions
workflow_steps─N:1→workflow_states
workflow_transitions─N:2→workflow_states(from + to)
workflow_templates─1:N→workflow_deployments
workflow_templates─1:N→workflow_template_versions
workflow_templates─1:N→workflow_tags
workflow_templates─1:N→workflow_template_audit
tasks─1:N→task_state_history
workflow_deployments─1:N→task_state_history

📊 ตัวอย่างข้อมูล · Sample Data

workflow_states (7 · master enum)

idname_thcolorsort
createdสร้างแล้วbrand0
assignedมอบหมายแล้วinfo1
in_progressกำลังทำwarn2
reviewรอตรวจwarn-dark3
doneเสร็จสิ้นsuccess4
blockedติดปัญหาdanger5
rejectedไม่ผ่านdanger-light6

workflow_templates (3 · in v2.0 seed)

idcodename_thcategorystepstransitions
1wf-tpl-qc-standardWorkflow มาตรฐาน QC ก่อสร้างqc78
2wf-tpl-simpleตรวจสอบอย่างง่าย (3 ขั้นตอน)simple32
3wf-tpl-double-pmตรวจคู่ + PM รับรองdouble-verify66

workflow_steps (QC standard · 7 steps · complete)

step_idstateroleSLA (hr)note_th
s-1createdQC Manager1สร้างงานตรวจและเลือก Checklist
s-2assignedQC Manager2มอบหมายให้ Inspector
s-3in_progressQC Inspector24ลงพื้นที่ตรวจตาม Checklist + ถ่ายรูป
s-4reviewQC Manager8ตรวจสอบผลและอนุมัติ
s-5doneQA0งานผ่านการตรวจรับ
s-6rejectedPM8ส่งกลับและมอบหมายผู้แก้ไข
s-7blockedPM4รอปลดล็อก

workflow_transitions (QC standard · 8 edges)

transitionfromtotriggerlabel_th
t-1createdassignedactionมอบหมาย Inspector
t-2assignedin_progressactionInspector รับงาน
t-3in_progressreviewpassส่งตรวจ
t-4reviewdonepassผ่านตรวจ
t-5reviewrejectedfailไม่ผ่านการตรวจ
t-6rejectedassignedautoส่งกลับ Assigned
t-7in_progressblockedactionติดปัญหา
t-8blockedin_progressactionปลดล็อก

task_state_history (runtime · task 1 · from created → done)

fromtotriggeractorelapsed (hr)transitioned_at
createdsystemSystem2026-04-01 09:00
createdassignedactionQC Manager0.52026-04-01 09:30
assignedin_progressactionQC Inspector2.02026-04-01 11:30
in_progressreviewpassQC Inspector22.02026-04-02 09:30
reviewdonepassQC Manager6.02026-04-02 15:30